#include <vector>
#include <functional>
#include <algorithm>

struct StudentInfo {
    int id;
    int chs;
    int math;
    int eng;
    int tot;
    StudentInfo(int v1, int v2, int v3, int v4, int v5)
    : id(v1), chs(v2), math(v3), eng(v4), tot(v5) {}
};

class WhoGetsReward {
    using S = StudentInfo;
    std::vector<S> data;
public:
    WhoGetsReward(int n) { data.reserve(n); }
    auto add(int id, int scores[]) {
        auto tot = scores[0] + scores[1] + scores[2];
        data.emplace_back(id, scores[0], scores[1], scores[2], tot);
    }
    auto solve(int rewards_num, std::function<bool(S const &, S const &)> cmp) {
        std::sort(data.begin(), data.end(), cmp);

        std::vector<S> result;
        auto i = data.begin();
        while (i != data.end() && rewards_num > 0) {
            result.push_back(*i);
            ++i;
            rewards_num -= 1;
        }

        return result;
    }
};

#include <iostream>

int main() {
    int num;
    
    std::cin >> num;

    WhoGetsReward inst(num);

    for (int id = 1; id <= num; ++id) {
        int s[3];
        std::cin >> s[0] >> s[1] >> s[2];
        inst.add(id, s);
    }

    for (auto const & i : inst.solve(5, [](auto const & a, auto const & b) {
        if (a.tot > b.tot) {
            return true;
        }
        else if (a.tot == b.tot) {
            if (a.chs > b.chs) {
                return true;
            }
            else if (a.chs == b.chs) {
                return a.id < b.id;
            }
            else {
                return false;
            }
        }
        else {
            return false;
        }
    })) {
        std::cout << i.id << " " << i.tot << "\n";
    }
}
